﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseFunction;
using BaseFunction.StaticTableClass;
using YFTOpenAPI.Model;

namespace YY.Web
{
    public partial class Center : LoginHelp
    {
        protected string KYZJ = "0";//可用资金
        protected string DJZJ = "0";//冻结资金（保证金将被冻结）
        private string ip = ConfigurationManager.AppSettings["ip"];
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitData();
                /*财务信息*/
                WalletInfo();
                
            }
        }
        /// <summary>
        /// 分红钱包
        /// </summary>
        private void WalletInfo()
        {
            YFTOpenAPI.Model.YiyangFunds yfModel=new YiyangFunds();
            string UserInfoID = base.GetSessionModel().amount;//银付通用户编号
            YFTOpenAPI.TransactionAPI openapi = new YFTOpenAPI.TransactionAPI("yiyang", ip, "27CAC2A3-F0C1-449C-8D59-62A9A263E48C");
            YFTOpenAPI.Model.ResponseData responseData = openapi.GetFunds(UserInfoID);
            if (responseData.statuscode == 1)
            {
                //查询成功
                List<YFTOpenAPI.Model.YiyangFunds> fundsinforlist = Newtonsoft.Json.JsonConvert.DeserializeObject<List<YFTOpenAPI.Model.YiyangFunds>>(responseData.data.ToString());
                a_DisplayDividendWallet.InnerText = fundsinforlist[0].DisplayDividendWallet;//分红钱包
                a_DisplayFinancialWallet.InnerText = fundsinforlist[0].DisplayFinancialWallet;//理财钱包
                a_DisplayCashWallet.InnerText = fundsinforlist[0].DisplayCashWallet;//现金钱包 钱包余额
                a_DisplayFrozen.InnerText = fundsinforlist[0].DisplayFrozen;//冻结资金
                a_DisplayAdPointWallet.InnerText = fundsinforlist[0].DisplayAdPointWallet;//广告点钱包
                a_DisplayIntegral.InnerText = fundsinforlist[0].DisplayIntegral;//积分
            }
            else
            {
                //错误信息
                string message = responseData.message;
            }
        }
        
        /// <summary>
        /// 初始化操作
        /// </summary>
        private void InitData()
        {
            string DXSYTS = "0";//短信剩余条数
            YY.Model.agent_users model_agent_users = base.GetSessionModel();
            litAreaName.Text = string.IsNullOrEmpty(model_agent_users.frozen_capital) ? "<a style=\"color: #005eac; cursor:pointer\" href=\"/MyAgent/AgentInfo.aspx\">缴纳保证金</a>[暂无代理资格]" : model_agent_users.area;
            litUserName.Text = string.IsNullOrEmpty(model_agent_users.user_name) ? "--" : model_agent_users.user_name;
            //DXSYTS = string.IsNullOrEmpty(model_agent_users.sms_account_balance) ? DXSYTS : OpenAPI.DecryptPar(model_agent_users.sms_account_balance);

            string SmsAccountBalance = "<font color='red' size='3'>" + DXSYTS + "</font> 条";
            ltl_SmsAccountBalance.Text = SmsAccountBalance;

            Model.agent_login_log model = new agent_login_log_Help().GetModel(model_agent_users.user_name, 1, YYEnums.ActionEnum.Login.ToString());
            if (model != null)
            {
                //本次登录
                litIP.Text = model.login_ip;
            }
            model = new agent_login_log_Help().GetModel(model_agent_users.user_name, 2, YYEnums.ActionEnum.Login.ToString());
            if (model != null)
            {
                //上一次登录
                litBackIP.Text = model.login_ip;
                litBackTime.Text = model.add_time.ToString();
            }
        }
    }
}